/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testingP;

import javax.persistence.EntityManager;
import javax.swing.DefaultCellEditor;
import javax.swing.table.TableCellEditor;
import model.DBManager;
import model.Vehicle;
import model.*;




import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.table.*;

import avenue.RoleBoxRenderer;

/**
 *
 * @author admin
 */
public class table_with_cb extends javax.swing.JFrame
{
    EntityManager em;
    Vehicle vehicle1;
    AppUser appUser1;
    boolean readOnly;
    
    
    private JComboBox roleCB2;
    RoleBoxRenderer r2;


    /**
     * Creates new form table_with_cb
     */
    public table_with_cb()
            
    {  
        
        em = DBManager.em;
        em.getTransaction().begin();
        roleCB2 = new JComboBox();
        //roleCB2.ad
        
        r2 = new avenue.RoleBoxRenderer();; 
//        roleCB2.setRenderer(r2);
        
//        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding2 = 
//                org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(
//                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
//                userRoleList, roleCB2);
//               bindingGroup.addBinding(jComboBoxBinding2);
//               
//        org.jdesktop.beansbinding.Binding binding2 = 
//                org.jdesktop.beansbinding.Bindings.createAutoBinding(
//                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
//                appUser2, 
//                org.jdesktop.beansbinding.ELProperty.create("${roleId}"),
//                roleCB2, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
//        bindingGroup.addBinding(binding2); 
        
        initComponents();
        
        
    //DefaultCellEditor dce1 = new DefaultCellEditor( roleCB );
    //editors.add( dce1 );
        
   // List<TableCellEditor> editors = new ArrayList<TableCellEditor>()  ;
   //  TableCellEditor editor = new DefaultCellEditor(comboBox);

        
        
        
   //TableCellEditor editor = new DefaultCellEditor(roleCB);
   //userTable.getColumnModel().getColumn(4).setCellEditor(editor);

   // TableCellRenderer r = new DefaultTableCellRenderer();
   //  userTable.getColumnModel().getColumn(4).setCellRenderer(r);
        

        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        appUser2 = appUser1;
        userRolesQuery = java.beans.Beans.isDesignTime() ? null : em.createQuery("select aus from UserRole aus");
        userRoleList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(userRolesQuery.getResultList());
        roleBoxRenderer1 = new avenue.RoleBoxRenderer();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        appUsersQuery = java.beans.Beans.isDesignTime() ? null : em.createQuery("select apu from AppUser apu");
        appUserList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(appUsersQuery.getResultList());
        r6661 = new testingP.TableCellUserRolesRenderer();
        jScrollPane2 = new javax.swing.JScrollPane();
        userTable = new javax.swing.JTable();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][]
            {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String []
            {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        r6661.setText("r6661");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, appUserList, userTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${FName}"));
        columnBinding.setColumnName("FName");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${LName}"));
        columnBinding.setColumnName("LName");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${password}"));
        columnBinding.setColumnName("Password");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${roleId}"));
        columnBinding.setColumnName("bbb");
        columnBinding.setColumnClass(model.UserRole.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane2.setViewportView(userTable);
        ///////////////////
        roleCB2.setRenderer(r2);
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding2 =
        org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(
            org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
            userRoleList, roleCB2);
        bindingGroup.addBinding(jComboBoxBinding2);

        org.jdesktop.beansbinding.Binding binding2 =
        org.jdesktop.beansbinding.Bindings.createAutoBinding(
            org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
            appUser2,
            org.jdesktop.beansbinding.ELProperty.create("${roleId}"),
            roleCB2, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding2);

        TableCellEditor editor = new DefaultCellEditor(roleCB2);
        DefaultTableCellRenderer tableRenderer = new DefaultTableCellRenderer();
        ///////////////////
        userTable.getColumnModel().getColumn(0).setResizable(false);
        userTable.getColumnModel().getColumn(1).setResizable(false);
        userTable.getColumnModel().getColumn(2).setResizable(false);
        userTable.getColumnModel().getColumn(3).setResizable(false);
        userTable.getColumnModel().getColumn(3).setCellEditor(editor);
        userTable.getColumnModel().getColumn(3).setCellRenderer(r6661);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 721, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 106, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(295, Short.MAX_VALUE))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try
          {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
              {
                if ("Nimbus".equals(info.getName()))
                  {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                  }
              }
          } catch (ClassNotFoundException ex)
          {
            java.util.logging.Logger.getLogger(table_with_cb.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (InstantiationException ex)
          {
            java.util.logging.Logger.getLogger(table_with_cb.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (IllegalAccessException ex)
          {
            java.util.logging.Logger.getLogger(table_with_cb.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (javax.swing.UnsupportedLookAndFeelException ex)
          {
            java.util.logging.Logger.getLogger(table_with_cb.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new table_with_cb().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private model.AppUser appUser2;
    private java.util.List<AppUser> appUserList;
    private javax.persistence.Query appUsersQuery;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private testingP.TableCellUserRolesRenderer r6661;
    private avenue.RoleBoxRenderer roleBoxRenderer1;
    private java.util.List<UserRole> userRoleList;
    private javax.persistence.Query userRolesQuery;
    private javax.swing.JTable userTable;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
